using System;
using System.Collections.Generic;
using System.Text;

namespace Acms.DataControls
{
    [System.ComponentModel.Designer(typeof(TopicFileDataSourceDesigner))]
    [System.Web.UI.ToolboxData("<{0}:TopicFileDataSource runat=server></{0}:TopicFileDataSource>")]
    public class TopicFileDataSource : GenericDataSource<Bll.TopicFile>
    {
        public enum Fields
        {
            Id,
            TypeId,
            FileId,
            Name,
            ConcurencyId
        }

        protected override Acms.Bll.TopicFile PopulateData(UpdateAction action, System.Collections.IDictionary keys, System.Collections.IDictionary values, System.Collections.IDictionary oldValues)
        {
            Bll.TopicFile tmp = null;
            byte[] concurencyId = null;
            if (action == UpdateAction.Insert)
            {
                tmp = Bll.TopicFile.CreateInstance();
            }
            else
            {
                int id = GetValue<int>(Fields.Id, keys);
                concurencyId = GetValue<byte[]>(Fields.ConcurencyId, keys);
                tmp = Bll.TopicFile.GetById(id);
            }

            if (tmp != null)
            {
                tmp.CheckConcurent(concurencyId);

                if (RequiresUpdate<int>(Fields.Name, values, oldValues))
                {
                    tmp.Name = GetValue<string>(Fields.Name, values);
                }
            }

            return tmp;
        }

        protected override int SaveChanges(Acms.Bll.TopicFile item)
        {
            item.Update();
            return 1;
        }

        protected override int Delete(Acms.Bll.TopicFile item)
        {
            item.Delete();
            return 1;
        }

    }

    public class TopicFileDataSourceDesigner : GenericDataSourceDesigner<Bll.TopicFile>
    {
        protected override Acms.Bll.TopicFile GetDesignTimeItem(int index)
        {
            return Acms.Bll.TopicFile.CreateInstance();
        }
    }
}
